package com.gotloop.jdo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.gotloop.enu.Role;

/**
 * User is a gotLoop user that can post and comment loops.
 * It is linked to an appengine User.
 * @author jibhaine
 *
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class UserProfile implements Serializable {

	/**
	 * Generated serial version UID.
	 */
	private static final long serialVersionUID = -8452339522916381415L;

	/**
	 * User Primary Key.
	 */
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	/**
	 * User name.
	 */
	@Persistent
	private String name;

	/**
	 * User password.
	 */
	@Persistent
	private String pass;

	/**
	 * User email.
	 */
	@Persistent
	private String email;

	/**
	 * User website url.
	 */
	@Persistent
	private String site;

	/**
	 * User description.
	 */
	@Persistent
	private String description;

	/**
	 * user role (ADMIN,USER,GUEST).
	 */
	@Persistent
	private Role role;

	/**
	 * Loops uploaded by User.
	 */
	@Persistent(mappedBy = "author")
	private List<Loop> uploadedLoops;
	
	/**
	 * Comments made.
	 */
	@Persistent(mappedBy = "author")
	private List<Comment> comments;

	/**
	 * Date of creation.
	 */
	@Persistent
	private Date creationDate;

	/**
	 * user last connection date.
	 * Used to purge user table (>12months).
	 */
	@Persistent
	private Date lastConnectDate;
	
	/**
	 * Constructor using fields.
	 * @param pLang		String language code	
	 * @param pName		User name
	 * @param pPass		User password
	 * @param pEmail	User email
	 * @param pSite		User site
	 * @param pDescription	User description
	 * @param pRole	User Roles
	 */
	public UserProfile(String pName, String pPass, String pEmail, String pSite,
			String pDescription, String pLang, Role pRole) {
		super();
		this.name = pName;
		this.pass = pPass;
		this.email = pEmail;
		this.site = pSite;
		this.description = pDescription;
		this.role = pRole;
		this.creationDate = new Date();
		this.lastConnectDate = new Date();
	}

	/**
	 * Public empty Constructor.
	 */
	public UserProfile() {
		super();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "User [name=" + name + ", email=" + email + ", role=" + role
				+ ", creationDate=" + creationDate + "]";
	}

	/**
	 * Get accessor for key.
	 * @return the key to get
	 */
	public Key getKey() {
		return key;
	}

	/**
	 * Set accessor for key.
	 * @param pKey the key to set
	 */
	public void setKey(Key pKey) {
		this.key = pKey;
	}

	/**
	 * Get accessor for name.
	 * @return the name to get
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set accessor for name.
	 * @param pName the name to set
	 */
	public void setName(String pName) {
		this.name = pName;
	}

	/**
	 * Get accessor for pass.
	 * @return the pass to get
	 */
	public String getPass() {
		return pass;
	}

	/**
	 * Set accessor for pass.
	 * @param pPass the pass to set
	 */
	public void setPass(String pPass) {
		this.pass = pPass;
	}

	/**
	 * Get accessor for email.
	 * @return the email to get
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Set accessor for email.
	 * @param pEmail the email to set
	 */
	public void setEmail(String pEmail) {
		this.email = pEmail;
	}

	/**
	 * Get accessor for site.
	 * @return the site to get
	 */
	public String getSite() {
		return site;
	}

	/**
	 * Set accessor for site.
	 * @param pSite the site to set
	 */
	public void setSite(String pSite) {
		this.site = pSite;
	}

	/**
	 * Get accessor for description.
	 * @return the description to get
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Set accessor for description.
	 * @param pDescription the description to set
	 */
	public void setDescription(String pDescription) {
		this.description = pDescription;
	}

	/**
	 * Get accessor for role.
	 * @return the role to get
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * Set accessor for role.
	 * @param pRole the role to set
	 */
	public void setRole(Role pRole) {
		this.role = pRole;
	}

	/**
	 * Get accessor for uploadedLoops.
	 * @return the uploadedLoops to get
	 */
	public List<Loop> getUploadedLoops() {
		return uploadedLoops;
	}

	/**
	 * Set accessor for uploadedLoops.
	 * @param pUploadedLoops the uploadedLoops to set
	 */
	public void setUploadedLoops(List<Loop> pUploadedLoops) {
		this.uploadedLoops = pUploadedLoops;
	}

	/**
	 * Get accessor for comments.
	 * @return the comments to get
	 */
	public List<Comment> getComments() {
		return comments;
	}

	/**
	 * Set accessor for comments.
	 * @param pComments the comments to set
	 */
	public void setComments(List<Comment> pComments) {
		this.comments = pComments;
	}


	/**
	 * Get accessor for creationDate.
	 * @return the creationDate to get
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * Set accessor for creationDate.
	 * @param pCreationDate the creationDate to set
	 */
	public void setCreationDate(Date pCreationDate) {
		this.creationDate = pCreationDate;
	}

	/**
	 * Get accessor for lastConnectDate.
	 * @return the lastConnectDate to get
	 */
	public Date getLastConnectDate() {
		return lastConnectDate;
	}

	/**
	 * Set accessor for lastConnectDate.
	 * @param pLastConnectDate the lastConnectDate to set
	 */
	public void setLastConnectDate(Date pLastConnectDate) {
		this.lastConnectDate = pLastConnectDate;
	}
	
}
